<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Show detailed information of an association (user).
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.2
 * 
 * 0.2)  Adds the markstar widget!
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_action.php';
require_once INSTALLDIR . '/lib/slh_util.php';
require_once INSTALLDIR . '/lib/slh_weibo.php';
require_once INSTALLDIR . '/lib/slh_markstar.php';

require_once INSTALLDIR . '/classes/Association.php';
require_once INSTALLDIR . '/classes/Avatar.php';


class AssociationAction extends Action
{
	/**
	 * The Association object.
	 */
	var $association = null;
	
	
	function title()
	{
		return $this->association->cnname . ' @社团';
	}
	
	function prepare($args)
	{
// TODO: Check logged in and rights.
		parent::prepare($args);
		
		// Parameter from 'get' url
		$user_id = $this->getTrimmedArg('guser_id');
		
		if ( !is_numeric($user_id)) {
			return false;
		}
		
		// Get the association(user).
		$this->association = Association::staticGet('user_id', $user_id);
		if (empty($this->association)) {
			$this->clientError('没有这个社团呃.');
		}
		
		return true;
	}
	
	function handle($args)
	{
		parent::handle($args);

		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			;
		} else {
			// Increase the some statistics.
			
			$this->showPage();
		}
	}
	
	/**
	 * Add the jRating stylesheet.
	 */
	function showStylesheets()
	{
		parent::showStylesheets();
		
		$this->cssLink('theme/base/css/jquery.jRating.css', 'base', 'screen, projection, tv');
	}
	
	/**
	 * Add the jRating scripts.
	 */
	function showScripts()
	{
		parent::showScripts();

		$this->script('jRating/jquery.jRating.min.js');
		$this->script('widget/markstar.go.js');
	}
	
	/**
	 * Overrideing the showInnerContent().
	 */
	function showInnerContent()
	{
		$this->element('h3', null, $this->association->cnname);
		
		$this->elementStart('div', 'cls_div_association');
		// Check if has a posted avatar.
		// Get the avatar url.
		$normalAvatar = Avatar::getAvatarBySize($this->association->user_id, AVATAR_NORMAL_SIZE);
		if ( !empty($normalAvatar)) {
			$this->elementStart('div', 'cls_div_avatar');
			$this->element('img', array('src' => $normalAvatar->avatarurl(),
										'max-width' => AVATAR_NORMAL_SIZE,
										'max-height' => AVATAR_NORMAL_SIZE));
			$this->elementEnd('div');
		} else {
			$this->elementStart('div', 'cls_div_avatar');
			$this->element('img', array('src' => Avatar::defaultImage(AVATAR_NORMAL_SIZE),
										'max-width' => AVATAR_NORMAL_SIZE,
										'max-height' => AVATAR_NORMAL_SIZE));
			$this->elementEnd('div');
		}
		
		$this->raw('<span class="cls_span_associationitem">' .
				   '类别: ' .
				   $this->association->getCatagoryName() .
				   '</span>');
		
		$this->raw('<span class="cls_span_associationitem">' .
				   '中文名称: ' .
				   $this->association->cnname .
				   '</span>');
				   		   
		$this->raw('<span class="cls_span_associationitem">' .
				   '英文名称: ' .
				   $this->association->enname .
				   '</span>');
				   
		$markstar = new MarkStar($this->association->user_id, $this);
		$markstar->show();
		
		$this->element('h5', null, '社团介绍: ');
		$this->elementStart('div', 'cls_div_rendered');
		try {
			$this->raw(slh_uncompress($this->association->rendered));
		} catch (Exception $e) {
			$this->raw($this->association->rendered);
		}
		$this->elementEnd('div');
		
		$this->elementEnd('div');
	}
	
// Overrided ends //////////////////////////////////////////////////////////////
	/**
	 * Remove the aside.
	 * Show the content of weibo.
	 * 
	 * FIXME: For $association or $profile in the session.
	 */
	function showInnerAside()
	{
		if ( !empty($this->association->weibo_id)) {
			$weibo = new Weibo($this, $this->association->weibo_id, $this->association->cnname);
			$weibo->show();
		} else {
			parent::showInnerAside();
		}
	}
}

?>